package com.navinfo.opentsp.platform.computing.service.huashen;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.googlecode.protobuf.format.JsonFormat;
import com.navinfo.opentsp.platform.computing.anno.RoutingProtocol;
import com.navinfo.opentsp.platform.computing.enums.ProtocolEnum;
import com.navinfo.opentsp.platform.computing.enums.YardEnum;
import com.navinfo.opentsp.platform.computing.service.IProtocolParseService;
import com.navinfo.opentsp.platform.location.protocol.common.LCLocationData;
import org.apache.flume.Event;

import java.util.Arrays;


@RoutingProtocol(yard= YardEnum.HUASHEN, protocolType = ProtocolEnum.LOCATION_DATA)
public class LocationDataHuaShenService implements IProtocolParseService {
    @Override
    public String parseProtocol(Event event) {
       try{
           LCLocationData.LocationData message = LCLocationData.LocationData.parseFrom(event.getBody());
           String preResult = JsonFormat.printToString(message);
           JSONObject jsonObject = JSON.parseObject(preResult);
           jsonObject.put("additionAlarm", Arrays.toString(message.getAdditionAlarm().toByteArray()));
           jsonObject.remove("partTime");
           jsonObject.remove("hashtid");
           return jsonObject.toJSONString();
       } catch(Exception e) {
           throw new RuntimeException(e);
       }
    }
}
